﻿using Volo.Abp.Authorization.Permissions;
using Volo.Abp.UI.Navigation;
using YAPACS.RisServer.Localization;

namespace YAPACS.RisServer.Menus;

public class RisServerMenuContributor : IMenuContributor
{
    public async Task ConfigureMenuAsync(MenuConfigurationContext context)
    {
        if (context.Menu.Name == StandardMenus.Main)
        {
            await ConfigureMainMenuAsync(context);
        }
        else if (context.Menu.Name == StandardMenus.User)
        {
            await ConfigureUserMenuAsync(context);
        }
    }

    private Task ConfigureMainMenuAsync(MenuConfigurationContext context)
    {
        var mainMenu = context.Menu;
        var l = context.GetLocalizer<RisServerResource>();

        mainMenu.AddItem(new ApplicationMenuItem(
            RisServerMenus.Home,
            l["Menu:Home"],
            "~/",
            icon: "fas fa-home",
            order: 0
        ).RequireAuthenticated());

        mainMenu.AddItem(new ApplicationMenuItem(
            RisServerMenus.ExamRegister,
            l["Menu:Exam:Register"],
            "~/register/index",
            icon: "fas fa-pencil-square",
            order: 0,
            requiredPermissionName: "登记"
        ).RequireAuthenticated());

        mainMenu.AddItem(new ApplicationMenuItem(
            RisServerMenus.Queuing,
            l["Menu:Exam:Queuing"],
            "~/technician/index",
            icon: "fas fa-male",
            order: 0,
            requiredPermissionName: "队列"
        ).RequireAuthenticated());

        mainMenu.AddItem(new ApplicationMenuItem(
            RisServerMenus.Technician,
            l["Menu:Exam:Technician"],
            "~/technician/index",
            icon: "fas fa-heartbeat",
            order: 0,
            requiredPermissionName: "技师"
        ).RequireAuthenticated());

        mainMenu.AddItem(new ApplicationMenuItem(
            RisServerMenus.Report,
            l["Menu:Exam:Report"],
            "~/report/index",
            icon: "fas fa-user-md",
            order: 0,
            requiredPermissionName: "报告"
        ).RequireAuthenticated());

        mainMenu.AddItem(new ApplicationMenuItem(
            RisServerMenus.QC,
            l["Menu:Exam:QC"],
            "~/qc/index",
            icon: "fas fa-shield-check",
            order: 0,
            requiredPermissionName: "质控"
        ).RequireAuthenticated());

        mainMenu.AddItem(new ApplicationMenuItem(
            RisServerMenus.Statistic,
            l["Menu:Exam:Statistic"],
            "~/statistic/index",
            icon: "fas fa-area-chart",
            order: 0,
            requiredPermissionName: "统计"
        ).RequireAuthenticated());

        return Task.CompletedTask;
    }

    private Task ConfigureUserMenuAsync(MenuConfigurationContext context)
    {
        var l = context.GetLocalizer<RisServerResource>();

        context.Menu.AddItem(new ApplicationMenuItem(
            "Account.ClearCache",
            l["ClearCache"],
            url: "#",
            icon: "fa fa-ban",
            cssClass: "account-clear-cache",
            order: int.MaxValue - 999));

        context.Menu.AddItem(new ApplicationMenuItem(
            "Account.ChangePassword",
            l["ChangePassword"],
            url: "#",
            icon: "fa fa-lock",
            cssClass: "account-change-password",
            order: int.MaxValue - 998));

        context.Menu.AddItem(new ApplicationMenuItem(
            "Account.Logout",
            l["Logout"],
            url: "~/Account/Logout",
            icon: "fa fa-power-off",
            order: int.MaxValue - 997));

        return Task.CompletedTask;
    }
}
